package com.kc.web.controller.business;

import com.kc.business.domain.BizArtisanEnterForm;
import com.kc.business.domain.BizLiteraryEnterForm;
import com.kc.business.service.IBizArtisanEnterService;
import com.kc.common.annotation.Log;
import com.kc.common.annotation.RepeatSubmit;
import com.kc.common.core.controller.BaseController;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.core.page.TableDataInfo;
import com.kc.common.enums.BusinessType;
import com.kc.common.utils.DictUtils;
import com.kc.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @author zhangshuo
 * @version 1.0
 * @date 2020/9/25
 */
@RestController
@RequestMapping("/business/artisanEnter")
public class BizArtisanEnterController extends BaseController {

    @Autowired
    private IBizArtisanEnterService artisanEnterService;

    /**
     * 入驻列表
     *
     * @param artisanEnterForm
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:celebrityEnter:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizArtisanEnterForm artisanEnterForm) {
        startPage();
        List<BizArtisanEnterForm> list = artisanEnterService.getList(artisanEnterForm);
        for (BizArtisanEnterForm form : list) {
            if (StringUtils.isNotBlank(form.getLicense())) {
                //字符串转景点类型数组
                form.setLicenseImgs(StringUtils.split(form.getLicense(), ","));
            }
            if (StringUtils.isNotBlank(form.getOpus())) {
                //字符串转景点类型数组
                form.setOpusImgs(StringUtils.split(form.getOpus(), ","));
            }
            form.setIndustryLabel(DictUtils.getDictLabel("industry_type", form.getIndustry()));
            form.setTitleLabel(DictUtils.getDictLabel("title_type", form.getTitle()));

        }
        return getDataTable(list);
    }


    /**
     * 修改入驻
     *
     * @param artisanEnterForm
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:celebrityEnter:edit')")
    @Log(title = "匠人入驻管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@Validated @RequestBody BizArtisanEnterForm artisanEnterForm) {
        return toAjax(artisanEnterService.edit(artisanEnterForm));
    }
}
